<template>
    <div>
            <p>用户名： <input type="text" v-model="username"></p>
            <p>密码： <input type="text" v-model="passoword"> </p>
            <button @click="login">登录</button>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    data() {
        return {
                base_url : "http://127.0.0.1:8000",
                username:"",
                passoword:"",
                name:"",
                token:""
        }
    },
    methods: {
           login(){
               let form_data=new FormData()
               form_data.append("username",this.username)
               form_data.append("password",this.passoword)
               axios({
                   url : this.base_url +"/app01/login/",
                   method:"post",
                   data:form_data
               }).then(res=>{
                   console.log(res.data)
                   if(res.data.code==200){
                       sessionStorage.setItem("name",res.data.username)
                       sessionStorage.setItem("token",res.data.token)
                       sessionStorage.setItem("fen",res.data.fen)
                       this.$router.push({name: 'show_2'})
                   }
               })
           }
    },
    created() {

    }
}
</script>

<style scoped>

</style>
